﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using Newtonsoft.Json;
using Wosperry.ExpressionExtensions;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Box> boxes = new List<Box>() {
                new (){Weight=100,Width = 10},
                new (){Weight=200,Width = 20},
                new (){Weight=300,Width = 30},
                new (){Weight=400,Width = 40},
                new (){Weight=500,Width = 50},
                new (){Weight=600,Width = 60},
                new (){Weight=700,Width = 70},
                new (){Weight=800,Width = 80},
                new (){Weight=900,Width = 90},
                new (){Weight=100,Width = 100},
                new (){Weight=110,Width = 110},
            };

            var result = boxes.GetList(new BoxQuery
            {
                MaxWidth = 60,
                MaxWeight = 400
            });
            var lengths = result.Select(x => x.Width);

            var queryable = boxes.AsQueryable();
            var lambda = queryable.BuildLambda(new BoxQuery { MinWidth = 70 });
            queryable.Where(lambda);
        }
    }

    /// <summary>
    /// parameters class (may be deserialized by json and some may be null)
    /// </summary>
    public class BoxQuery
    {
        [WhereLarger("Width")]
        public float? MinWidth { get; set; }

        [WhereSmallerEqual("Width")]
        public float? MaxWidth { get; set; }

        [WhereSmallerEqual("Weight")]
        public float? MaxWeight { get; set; }
    }

    /// <summary>
    /// Box
    /// </summary>
    public class Box
    {
        public int Id { get; set; }
        public float Width { get; set; }
        public float Height { get; set; }
        public float Weight { get; set; }
        public string Description { get; set; }
        public string Remark { get; set; }
    }
}
